package uit.comstore.controller;

import java.util.List;
import uit.comstore.model.blo.ManufacturerBLO;
import uit.comstore.model.entity.Manufacturer;

public class ManufacturerAction{
	private ManufacturerBLO manufacturerBLO;
	private List<Manufacturer> manufacturerList;
	private Manufacturer manufacturer;
	private Long id;

	public ManufacturerAction(){
		manufacturerBLO = new ManufacturerBLO();
	}

	public String execute(){
		this.manufacturerList = manufacturerBLO.list();
		return "success";
	}

	public String add(){
		try{
			Manufacturer manufacturer = getManufacturer();
			if(manufacturer.getImage().isEmpty()){
				manufacturer.setImage("default.png");
			}
			manufacturerBLO.add(manufacturer);
		}catch(Exception ex){
			//System.out.println("Cannot add manufacturer!");
		}
		return "success";
	}
	
	public String delete(){
		manufacturerBLO.delete(getId());
		return "success";
	}
	
	public String edit() {
		try{
			Manufacturer manufacturer = getManufacturer();
			if(manufacturer.getImage().isEmpty()){
				manufacturer.setImage("default.png");
			}
			manufacturerBLO.update(manufacturer);
		}catch(Exception ex){
			//System.out.println("Cannot add Customer!");
		}
		return "success";
	}

	public List<Manufacturer> getManufacturerList() {
		return manufacturerList;
	}

	public void setManufacturerList(List<Manufacturer> manufacturerList) {
		this.manufacturerList = manufacturerList;
	}

	public Manufacturer getManufacturer() {
		return manufacturer;
	}

	public void setManufacturer(Manufacturer manufacturer) {
		this.manufacturer = manufacturer;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}


}
